package com.cy.dda.service.message.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.cy.dda.comm.annotation.Message;
import com.cy.dda.comm.constant.Constants;
import com.cy.dda.dao.mapper.cases.CasesMapper;
import com.cy.dda.model.enums.MessageType;
import com.cy.dda.service.BaseService;
import com.cy.dda.service.message.MessageService;
import com.cy.dda.service.wechat.WechatService;

/**
 * 消息service唯一实现类
 *
 * @author: tanyilin
 * @create: 2018年12月11日 下午4:03:12
 */
@Service("messageService")
@Primary
public class MessageServiceImpl extends BaseService implements MessageService {

	@Autowired
    protected WechatService wechatService;
	@Autowired
	protected CasesMapper casesMapper;
	
	private static Map<MessageType, MessageServiceImpl> messageServiceMap = new HashMap<MessageType, MessageServiceImpl>();
	
	/**
	 * 初始化messageServiceMap
	 * 
	 */
	@PostConstruct
	public void initMap() {
		Message message = this.getClass().getAnnotation(Message.class);
		if(message == null) {
			return;
		}
		messageServiceMap.put(message.type(), this);
	}
	
	@Override
	@Async(Constants.ASYNC)
	public void sendMessage(String message, MessageType messageType) {
		//执行发送消息的方法
		messageServiceMap.get(messageType).execute(message);
	}

	/**
	 * 真正执行发送消息的方法
	 * 
	 * @param message
	 */
	public void execute(String message) {

    }
	
}
